<?php

class Admin_CategoryController extends ControllerAction_Abstract  {
	public function listAction(){	
		$id = $this->_pageInfo->getId ();	
		$actionType = $this->getParam('do');
		$actionType = empty($actionType)?ActionHelper_ActionListWithPost::ACTION_NEW:$actionType;
		$this->view->form_ajaxid = 'mainbody';		
		$options[ActionHelper_ActionListWithPost::OPTIONS_FORM] = $this->_getForm($id,$actionType);
		$options[ActionHelper_ActionListWithPost::OPTIONS_ACTION_TYPE] = $actionType;
		$options[ActionHelper_ActionListWithPost::OPTIONS_INIT_ID] = $id;
		$options[ActionHelper_ActionListWithPost::OPTIONS_PAGELIST_WHERE_ARRAY]['user_id = ?'] = $this->_loginUser->id ;	
		$options[ActionHelper_ActionListWithPost::OPTIONS_MODULE_SELECT] = Module_Impl_Category_Select::getInstance();
		$options[ActionHelper_ActionListWithPost::OPTIONS_MODULE_OPRATION] = Module_Impl_Category_Opration::getInstance();
		$options[ActionHelper_ActionListWithPost::OPTIONS_PAGELIST_PAGENUMBER] = 4;
		$options[ActionHelper_ActionListWithPost::OPTIONS_PAGELIST_ENABLE] = false;
		$this->_helper->actionListWithPost->setOptions ( $options );		
		$this->_helper->actionListWithPost->process ();			
	}	
	
	protected function _getForm($id,$actionType){
		$form = new Form_Category_New();
		if (! empty ( $id ) and $actionType == ActionHelper_ActionListWithPost::ACTION_EDIT) {
			$form->getElement ( 'submit' )->setLabel ( $this->_ ( 'edit' ) );
		} else {
			$form->getElement ( 'submit' )->setLabel ( $this->_ ( 'new' ) );
		}
		
		$elementUserid = $form->getElement ( 'user_id' );
		$elementUserid->setValue($this->_loginUser->id);
		
		if ($actionType == ActionHelper_ActionListWithPost::ACTION_EDIT) {
			$url = $this->_pageInfo->getCurrentUrl () . '/do/' . $actionType;
		} else {
			$url = $this->_pageInfo->getCurrentUrl () ;
		}		
		if(!empty($id)){
			$url .= '/id/' . $id;
		}
		$form->setAttrib ( 'action', $url );
		return $form;
	}
}